<template>
	<view class="release-order">
		<u-sticky :offsetTop="top">
			<view class="tabs">
				<u-tabs ref="tabs" :list="list1" :scrollable="false" :current="current" @change="tabschange"></u-tabs>
			</view>
		</u-sticky>
		<view>
			<listcardorder v-for="(item, key) in list" :dicts="dicts" :item="item" :levelTypeList="levelTypeList"
				:key="key">
			</listcardorder>
			<u-loadmore :status="status"></u-loadmore>
			<view class="" style="height: 10rpx"> </view>
		</view>
	</view>
</template>

<script>
	import listcardorder from "./listcardorder.vue";
	import {
		getReleasePage
	} from "@/api/release.js";
	import {
		getDicts
	} from "@/api/dictdata";
	import {
		getProductClassAll
	} from "@/api/index.js";
	export default {
		components: {
			listcardorder,
		},
		data() {
			return {
				top: `${uni.$u.addUnit(
        uni.$u.getPx(uni.$u.props.navbar.height) +
        uni.$u.sys().statusBarHeight,
        "px"
      )}`,
				dicts: {},
				levelTypeList: [],
				current: 0,
				list: [],
				status: "loadmore",
				list1: [{
						name: "全部",
						query: {
							auditStatus: "",
						},
					},
					{
						// 0待审核 1已通过 2审核失败 3草稿
						name: "草稿",
						query: {
							auditStatus: "3",
						},
					},
					{
						// 0未审核 1审核通过 2审核失败
						name: "待审核",
						query: {
							auditStatus: "0",
						},
					},
					{
						name: "已通过",
						query: {
							auditStatus: "1",
						},
					},
					{
						name: "未通过",
						query: {
							auditStatus: "2",
						},
					},
				],
			};
		},

		mounted() {
			this.datainit();
		},
		computed: {
			reqdata() {
				let r = {};
				r.auditStatus = this.list1[this.current].query.auditStatus;
				r.pageSize = 10;
				r.pageNo = Math.ceil(this.list.length / r.pageSize) + 1;

				return r;
			},
		},
		methods: {
			async datainit() {
				const res = await getProductClassAll();
				this.levelTypeList = res.data;
				let {
					data
				} = await getDicts("transactional_mode,manage_model");

				let transactional_mode = data.filter((e) => {
					return e.dictType == "transactional_mode";
				});
				let manage_model = data.filter((e) => {
					return e.dictType == "manage_model";
				});
				this.dicts = {
					transactional_mode,
					manage_model,
				};
			},
			swiperchange(current) {
				this.$refs.tabs.clickHandler({}, current.detail.current);
			},
			tabschange(current) {
				this.current = current.index;
				this.init();
			},
			async getData() {
				this.status = "loading";
				uni.showLoading();
				let data = await getReleasePage(this.reqdata);
				this.list = this.list.concat(data.data.list);
				uni.hideLoading();
				this.status =
					data.data.list.length >= this.reqdata.pageSize ? "more" : "noMore";
			},
			init() {
				this.list = [];
				this.getData();
			},
		},
	};
</script>

<style lang="scss">
	.release-order {

		// display: flex;
		// flex-direction: column;
		// padding-bottom: 40rpx;
		.tabs {
			background: #fff;
		}

		.swiper {
			flex: 1;
			height: 0;
		}
	}
</style>